jQuery(document).ready(function() {
    bindDicName();
    bindDicMethod();
});
function bindDicName() {
    jQuery("input[dicName]").each(function() {
        var element = jQuery(this);
        var entityName = element.attr("dicName");
        var tagetName = element.attr("name");
        var handle = element.attr("callBack");
        var param = element.attr("callBackParam");
        var parent = element.attr("prefix");
        var refer = element.attr("refer");
        var filter = element.attr("filter");
        var formName = element.attr("formName");
        if (handle == undefined) {
            handle = "";
        }
        if (param == undefined) {
            param = "";
        }
        if (filter == undefined) {
            filter = "";
        }
        if (parent == undefined) {
            parent = "";
        }
        if (formName == undefined) {
            formName = "submitForm";
        }
        var nameHidden = element.attr("refName");
        if (nameHidden == undefined) {
            nameHidden = tagetName.substr(0, tagetName.length - 5);
        }
        new CAPXOUS.AutoComplete(tagetName, function() {
            if (refer != undefined) {
                parent = jQuery("#" + refer).val();
                filter = "ref";
            }
            return BASE_PATH + "dictionary/showList?dicName=" + entityName + "&parent=" + parent + "&filter=" + filter + "&dmName=dm&mcName=mc&orderKey=xh&handle=" + handle + "&param=" + param;
        }, {
            formName:formName,
            formTarget:[nameHidden],
            javaTarget:['dm'],
            javaSource:['mc'],
            width:160
        });
    });
}
function bindDicMethod() {
    jQuery("input[dicMethod]").each(function() {
        var element = jQuery(this);
        var event = element.attr("dicMethod");
        var tagetName = element.attr("name");
        var handle = element.attr("callBack");
        var formName = element.attr("formName");
        if (handle == undefined) {
            handle = "";
        }
        if (formName == undefined) {
            formName = "submitForm";
        }
        var nameHidden = element.attr("refName");
        if (nameHidden == undefined) {
            nameHidden = tagetName.substr(0, tagetName.length - 5);
        }
        new CAPXOUS.AutoComplete(tagetName, function() {
            return BASE_PATH + "dictionary/showList?dicName=" + event + "&handle=" + handle;
        }, {
            formName:formName,
            formTarget:[nameHidden],
            javaTarget:['dm'],
            javaSource:['mc'],
            width:160
        });
    });
}
function selectDic(obj) {
    var item = jQuery(obj)
    var itemName = item.attr("name");
    var hiddenName = itemName.substr(0, itemName.length - 5);
    var dicObj = jQuery("#DIC_CAPXOUS_" + itemName).find(".current");
    var value = dicObj.attr("code");
    if (value != undefined) {
        jQuery("#" + hiddenName).val(value)
        if (value == '') {
            var handle = item.attr("blankHandle");
            if (handle != undefined)eval(handle)
        } else {
            jQuery("#" + itemName).val(dicObj.attr("content"))
        }
    } else {
        jQuery("#" + hiddenName).val("")
    }
}